#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;



int** initialize(int n)
{
    srand (time(NULL));

    int** a=new int*[n];
    for(int i=0;i<n;i++)
    {
        a[i]=new int[n];

    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            a[i][j]=0;
        }

    }

    int num_genes=5;

    for(int i=0;i<num_genes;i++)
    {
        int x=rand()%n;
        int y=rand()%n;

        if(a[x][y]==1)
        {
        int x=rand()%n;
        int y=rand()%n;
        i--;
        }

        a[x][y]=1;

    }
return a;

}

void print(int** &tabla,int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<tabla[i][j]<<" ";
        }
        cout<<endl;

    }
}

int count_neighbors(int** &tablero,int x,int y)
{
    int neigh=0;

    if(tablero[x][y-1]==1)
        neigh++;
    if(tablero[x][y+1]==1)
        neigh++;
    if(tablero[x-1][y]==1)
        neigh++;
    if(tablero[x+1][y]==1)
        neigh++;
    if(tablero[x-1][y-1]==1)
        neigh++;
    if(tablero[x-1][y+1]==1)
        neigh++;
    if(tablero[x+1][y+1]==1)
        neigh++;
    if(tablero[x+1][y-1]==1)
        neigh++;

    return neigh;

}


int main()
{

    int** tablero=initialize(5);

    print(tablero,5);

    cout<<"el gen 3,3 tiene : "<<count_neighbors(tablero,0,0);




    return 0;
}
